package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/12/11 13:59
 */
public class MergeArrayTest {
    public static void main(String[] args) {

    }

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] temp = new int[m + n];
        int p = 0, q = 0;
        int i = 0;
        while (p < m && q < n) {
            if (nums1[p] < nums2[q]) {
                temp[i++] = nums1[p];
                p++;
            } else {
                temp[i++] = nums2[q];
                q++;
            }
        }
        while (p < m) {
            temp[i++] = nums1[p];
            p++;
        }
        while (q < n) {
            temp[i++] = nums2[q];
            q++;
        }

        System.arraycopy(temp, 0, nums1, 0, m + n);
    }
}
